package com.eduagent.xwqeduagent.controller;

import com.eduagent.xwqeduagent.api.CreativePosterGeneration.model.CreatePosterTaskResponse;
import com.eduagent.xwqeduagent.api.CreativePosterGeneration.model.GetPosterTaskResponse;
import com.eduagent.xwqeduagent.common.BaseResponse;
import com.eduagent.xwqeduagent.common.ResultUtils;
import com.eduagent.xwqeduagent.exception.BusinessException;
import com.eduagent.xwqeduagent.exception.ErrorCode;
import com.eduagent.xwqeduagent.model.dto.CreatePosterRequest;
import com.eduagent.xwqeduagent.service.PosterService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 创意海报生成接口
 */
@RestController
@RequestMapping("/poster")
@Slf4j
public class PosterController {

    @Resource
    private PosterService posterService;

    /**
     * 创建创意海报生成任务
     * 
     * @param createPosterRequest 创建海报请求
     * @return 任务创建响应
     */
    @PostMapping("/create_task")
    public BaseResponse<CreatePosterTaskResponse> createPosterTask(@RequestBody CreatePosterRequest createPosterRequest) {
        if (createPosterRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        
        // 记录请求参数
        log.info("接收到创意海报生成请求: title={}, promptTextZh={}, generateMode={}",
                createPosterRequest.getTitle(),
                createPosterRequest.getPromptTextZh(),
                createPosterRequest.getGenerateMode());
                
        CreatePosterTaskResponse response = posterService.createPosterTask(createPosterRequest);
        return ResultUtils.success(response);
    }

    /**
     * 查询创意海报生成任务状态
     * 
     * @param taskId 任务ID
     * @return 任务状态响应
     */
    @GetMapping("/task/{taskId}")
    public BaseResponse<GetPosterTaskResponse> getPosterTask(@PathVariable String taskId) {
        if (taskId == null || taskId.isEmpty()) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "任务ID不能为空");
        }
        
        log.info("接收到查询创意海报生成任务请求: taskId={}", taskId);
        GetPosterTaskResponse response = posterService.getPosterTask(taskId);
        return ResultUtils.success(response);
    }
} 